//
//  CourseListHeaderView.m
//  xpkc
//
//  Created by TopSageOSX on 14-8-25.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "CourseListHeaderView.h"

@implementation CourseListHeaderView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //
        [self creatHeaderView];
    }
    return self;
}
/**
 *  创建视图
 */
-(void)creatHeaderView{
    self.backgroundColor = [UIColor whiteColor];
    //创建控件
    self.titleLabel = [[UILabel alloc]init];
    UILabel *teacher = [[UILabel alloc]init];
    self.teacherLabel = [[UILabel alloc]init];
    UILabel *progress = [[UILabel alloc]init];
    self.progressLabel = [[UILabel alloc]init];
    UILabel *lectures = [[UILabel alloc]init];
    UILabel *laststudy = [[UILabel alloc]init];
    self.collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.lastStudyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //获取位置信息
    CGRect titleframe;
    CGRect teacherframe,teacher_name_frame;
    CGRect progressframe,progress_text_frame;
    CGRect lectureframe,lectures_text_frame;
    CGRect laststudyframe,laststudy_btn_frame;
    CGRect collectBtnframe;
    titleframe = CGRectMake(0, 5, SCREEN_WIDTH, 20);
    teacherframe = CGRectMake(SCREEN_WIDTH*0.1-5, 30, 70, 20);
    teacher_name_frame = CGRectMake(SCREEN_WIDTH*0.1-5+45, 30, 85, 20);
	
    //progressframe = CGRectMake(SCREEN_WIDTH*0.1-5, 55, 70, 20);
	lectureframe = CGRectMake(SCREEN_WIDTH*0.1-5, 55, 70, 20);
	
    //progress_text_frame = CGRectMake(SCREEN_WIDTH*0.1-5+70, 55, 60, 20);
	lectures_text_frame = CGRectMake(SCREEN_WIDTH*0.1-5+45, 55, 60, 20);
	collectBtnframe = CGRectMake(SCREEN_WIDTH*0.1-5, 55, 80, 20);
    if (isPad) {
        progressframe = CGRectMake(SCREEN_WIDTH*0.5, 30, 70, 20);
    }else{
        progressframe = CGRectMake(SCREEN_WIDTH*0.5-10, 30, 70, 20);
    }
    if (isPad) {
        progress_text_frame = CGRectMake(CGRectGetMaxX(progressframe)+10, 33, 80, 14);
    }else{
        progress_text_frame = CGRectMake(CGRectGetMaxX(progressframe)+5, 33, 80, 14);
    }
    if (isPad) {
        laststudyframe = CGRectMake(SCREEN_WIDTH*0.5, 55, 100, 20);
    }else{
        laststudyframe = CGRectMake(SCREEN_WIDTH*0.5-10, 55, 100, 20);
    }
    if (isPad) {
        laststudy_btn_frame = CGRectMake(SCREEN_WIDTH*0.5, 55, 100, 20);
    }else{
        laststudy_btn_frame = CGRectMake(SCREEN_WIDTH*0.5-10, 55, 100, 20);
    }
    self.titleLabel.frame = titleframe;
    teacher.frame = teacherframe;
    self.teacherLabel.frame = teacher_name_frame;
    progress.frame = progressframe;
    self.progressLabel.frame = progress_text_frame;
    lectures.frame = lectureframe;
    laststudy.frame = laststudyframe;
    self.lastStudyBtn.frame = laststudy_btn_frame;
    self.collectBtn.frame = collectBtnframe;
	
	//进度条视图
	UIView *progressBaseView = [[UIView alloc]init];
	progressBaseView.frame = progress_text_frame;
	progressBaseView.backgroundColor = [UIColor colorWithRed:0.86f green:0.86f blue:0.86f alpha:1.00f];
	[self addSubview:progressBaseView];
	
	_progressView = [[UIView alloc]init];
	_progressView.frame = CGRectMake(0, 0, 20, progressBaseView.bounds.size.height);
	_progressView.backgroundColor = [UIColor colorWithRed:1.00f green:0.80f blue:0.36f alpha:1.00f];
	[progressBaseView addSubview:_progressView];
	
    //详细属性
    
    UIFont *font = [UIFont systemFontOfSize:14];
    UIFont *titleFont = [UIFont systemFontOfSize:20];
    if (isPad) {
        font = [UIFont systemFontOfSize:16];
        titleFont = [UIFont systemFontOfSize:24];
    }else{
    }
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
//    self.titleLabel.textColor=[UIColor orangeColor];
    teacher.text = @"讲师:";
    teacher.textColor = [UIColor darkGrayColor];
    progress.text = @"学习进度:";
    progress.textColor = [UIColor darkGrayColor];
    lectures.text = @"只看收藏";
    lectures.textColor = RGBCOLOR(15, 196, 62);
    laststudy.text = @"继续上次学习";
    laststudy.textColor = RGBCOLOR(15, 196, 62);
    teacher.font = font;
    progress.font = font;
    laststudy.font = font;
    lectures.font = font;
    lectures.tag = 111;
    self.teacherLabel.textColor = [UIColor darkGrayColor];
    self.progressLabel.textColor = [UIColor darkGrayColor];
    self.titleLabel.backgroundColor = [UIColor clearColor];
    self.teacherLabel.font = font;
	self.progressLabel.font = [UIFont systemFontOfSize:11];
	self.progressLabel.textAlignment = NSTextAlignmentCenter;
    [self.collectBtn setImage:[UIImage imageNamed:@"heart_red"] forState:UIControlStateNormal];
    [self.collectBtn setImage:[UIImage imageNamed:@"heart_white"] forState:UIControlStateHighlighted];
    [self.collectBtn setImage:[UIImage imageNamed:@"heart_gray"] forState:UIControlStateSelected];
    self.collectBtn.imageEdgeInsets = UIEdgeInsetsMake(2, 60, 2, 2);
    [self.collectBtn addTarget:self action:@selector(favoriteClick:) forControlEvents:UIControlEventTouchUpInside];
    teacher.backgroundColor = [UIColor clearColor];
    self.teacherLabel.backgroundColor = [UIColor clearColor];
    progress.backgroundColor = [UIColor clearColor];
	self.progressLabel.backgroundColor = [UIColor clearColor];
    lectures.backgroundColor = [UIColor clearColor];
    laststudy.backgroundColor = [UIColor clearColor];
	
	self.lastBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    if (isPad) {
		self.lastBtn.frame = CGRectMake(laststudy.frame.origin.x+100, laststudy.frame.origin.y-5, 25, 25);
    }else{
		self.lastBtn.frame = CGRectMake(laststudy.frame.origin.x+90, laststudy.frame.origin.y-5, 25, 25);
    }
	[self.lastBtn setImage:[UIImage imageNamed:@"download-play-button.png"] forState:UIControlStateNormal];
	[self addSubview:self.lastBtn];
    
    //添加
    [self addSubview:self.titleLabel];
    [self addSubview:teacher];
    [self addSubview:self.teacherLabel];
    [self addSubview:progress];
    [self addSubview:self.progressLabel];
    [self addSubview:lectures];
    [self addSubview:laststudy];
    [self addSubview:self.lastStudyBtn];
    [self addSubview:self.collectBtn];
}

- (void)favoriteClick:(UIButton *)btn{
    UILabel *label =
    (UILabel *)[self viewWithTag:111];
    if (btn.selected) {
        btn.selected = NO;
        label.text = @"只看收藏";
    }else{
        btn.selected = YES;
        label.text = @"查看全部";
    }
}

@end
